﻿using System.Collections.Generic;
using System.ServiceModel;

namespace App.Utility.Paging
{
    /// <summary>
    /// Written By : Charles Cook
    /// 
    /// Contains a page response
    /// </summary>
    [MessageContract]
    public class PageResponse<T> : IPagedList
    {
        /// <summary>
        /// The paged data returned from the pager
        /// </summary>
        [MessageBodyMember]
        public List<T> Page { get; set; }

        /// <summary>
        /// The total number of pages in the data source
        /// </summary>
        [MessageBodyMember]
        public int TotalPages { get; set; }

        /// <summary>
        /// The current page for the 
        /// </summary>
        [MessageBodyMember]
        public int PageIndex { get; set; }

        /// <summary>
        /// Total items in the original data source
        /// </summary>
        [MessageBodyMember]
        public int TotalCount { get; set; }

        /// <summary>
        /// The size of each page of data
        /// </summary>
        [MessageBodyMember]
        public int PageSize { get; set; }

        
        public bool IsPreviousPage
        {
            get
            {
                return (PageIndex > 0);
            }
        }

        public bool IsNextPage
        {
            get
            {
                return ((PageIndex + 1) * PageSize) < TotalCount;
            }
        }
    }
}
